﻿<?xml version="1.0" encoding="UTF-8"?>
<!--This as a slightly changed version of the default MS Search Result XSLT file.
Properties which are not supported 1:1 from ESP are Commented in as they do not make sense.
This are mainly:
- Result sorting is not static but dynamic dependend on the search profile
- Alerting is not part of ESP
- RSS feed not impemented
- Scope is not part of ESP
- Discover Definitions is not implemented pout of the box
-->

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" >
  <xsl:output method="html"/>

  <xsl:param name="NoResults" />
  <xsl:param name="NoResults1" />
  <xsl:param name="NoResults2" />
  <xsl:param name="NoResults3" />
  <xsl:param name="NoResults4" />

  <!-- When empty result set is returned from search -->
  <xsl:template name="dvt_1.empty">
    <span class="srch-description" id="CSR_NO_RESULTS">
      <xsl:value-of select="$NoResults" />
      <ol>
        <li>
          <xsl:value-of select="$NoResults1" />
        </li>
        <li>
          <xsl:value-of select="$NoResults2" />
        </li>
        <li>
          <xsl:value-of select="$NoResults3" />
        </li>
        <li>
          <xsl:value-of select="$NoResults4" />
        </li>
      </ol>
    </span>
  </xsl:template>

  <!-- Main body template. -->
  <xsl:template name="dvt_1.body">
    <div class="srch-results">
      <xsl:apply-templates />
    </div>
  </xsl:template>
 
  <!-- This template is called for each result -->
  <xsl:template match="Result" >
    <xsl:variable name="id" select="id"/>
    <xsl:variable name="url" select="url"/>
    <span class="srch-Icon">
      <a href="{$url}" id="{concat('CSR_IMG_',$id)}" title="{$url}">
        <img align="absmiddle" src="{imageurl}" border="0" alt="{imageurl/@imageurldescription}" />
      </a>
    </span>
    <span class="srch-Title">
      <a href="{$url}" id="{concat('CSR_',$id)}" title="{$url}">
        <xsl:choose>
          <xsl:when test="hithighlightedproperties/HHTitle[. != '']">
            <xsl:call-template name="HitHighlighting">
              <xsl:with-param name="hh" select="hithighlightedproperties/HHTitle" />
            </xsl:call-template>
          </xsl:when>
          <xsl:otherwise>
            <xsl:value-of select="title"/>
          </xsl:otherwise>
        </xsl:choose>
      </a>
      <br/>
    </span>
    <div class="srch-Description">
      <xsl:choose>
        <xsl:when test="hithighlightedsummary[. != '']">
          <xsl:call-template name="HitHighlighting">
            <xsl:with-param name="hh" select="hithighlightedsummary" />
          </xsl:call-template>
        </xsl:when>
        <xsl:when test="description[. != '']">
          <xsl:value-of select="description" disable-output-escaping="yes"/>
        </xsl:when>
      </xsl:choose>
    </div >
    <p class="srch-Metadata">
      <span class="srch-URL">
        <a href="{$url}" id="{concat('CSR_U_',$id)}" title="{$url}" dir="ltr">
          <xsl:choose>
            <xsl:when test="hithighlightedproperties/HHUrl[. != '']">
              <xsl:call-template name="HitHighlighting">
                <xsl:with-param name="hh" select="hithighlightedproperties/HHUrl" />
              </xsl:call-template>
            </xsl:when>
            <xsl:otherwise>
              <xsl:value-of select="url"/>
            </xsl:otherwise>
          </xsl:choose>
        </a>
      </span>
      <xsl:call-template name="DisplaySize">
        <xsl:with-param name="size" select="size" />
      </xsl:call-template>
      <xsl:call-template name="DisplayString">
        <xsl:with-param name="str" select="author" />
      </xsl:call-template>
      <xsl:call-template name="DisplayString">
        <xsl:with-param name="str" select="write" />
      </xsl:call-template>
    </p>         
    
  </xsl:template>
  
  <xsl:template name="HitHighlighting">
    <xsl:param name="hh" />
    <xsl:apply-templates select="$hh"/>
  </xsl:template>

  <xsl:template match="ddd">
    &#8230;
  </xsl:template>
  <xsl:template match="space">
    <xsl:text xml:space="preserve"> </xsl:text>
  </xsl:template>
  <xsl:template match="c0">
    <b>
      <xsl:value-of select="."/>
    </b>
  </xsl:template>
  <xsl:template match="c1">
    <b>
      <xsl:value-of select="."/>
    </b>
  </xsl:template>
  <xsl:template match="c2">
    <b>
      <xsl:value-of select="."/>
    </b>
  </xsl:template>
  <xsl:template match="c3">
    <b>
      <xsl:value-of select="."/>
    </b>
  </xsl:template>
  <xsl:template match="c4">
    <b>
      <xsl:value-of select="."/>
    </b>
  </xsl:template>
  <xsl:template match="c5">
    <b>
      <xsl:value-of select="."/>
    </b>
  </xsl:template>
  <xsl:template match="c6">
    <b>
      <xsl:value-of select="."/>
    </b>
  </xsl:template>
  <xsl:template match="c7">
    <b>
      <xsl:value-of select="."/>
    </b>
  </xsl:template>
  <xsl:template match="c8">
    <b>
      <xsl:value-of select="."/>
    </b>
  </xsl:template>
  <xsl:template match="c9">
    <b>
      <xsl:value-of select="."/>
    </b>
  </xsl:template>

  <!-- The size attribute for each result is prepared here -->
  <xsl:template name="DisplaySize">
    <xsl:param name="size" />
    <xsl:if test='string-length($size) &gt; 0'>
      <xsl:if test="number($size) &gt; 0">
        -
        <xsl:choose>
          <xsl:when test="round($size div 1024) &lt; 1">
            <xsl:value-of select="$size" /> Bytes
          </xsl:when>
          <xsl:when test="round($size div (1024 *1024)) &lt; 1">
            <xsl:value-of select="round($size div 1024)" />KB
          </xsl:when>
          <xsl:otherwise>
            <xsl:value-of select="round($size div (1024 * 1024))"/>MB
          </xsl:otherwise>
        </xsl:choose>
      </xsl:if>
    </xsl:if>
  </xsl:template>
    
  <!-- A generic template to display string with non 0 string length (used for author and lastmodified time -->
  <xsl:template name="DisplayString">
    <xsl:param name="str" />
    <xsl:if test='string-length($str) &gt; 0'>
      -
      <xsl:value-of select="$str" />
    </xsl:if>
  </xsl:template>

  <xsl:template name="debug.body">
    <div class="srch-results">
      <p class="srch-Metadata">
        <table style="border">
          <xsl:for-each select="Result/*">
            <tr>
              <td>
                <xsl:value-of select="name(.)"/>
              </td>
              <td>
                <xsl:value-of select="."/>
              </td>
            </tr>
          </xsl:for-each>
          <xsl:for-each select="Result/*/*">
            <tr>
              <td>
                <xsl:value-of select="name(.)"/>
              </td>
              <td>
                <xsl:value-of select="." disable-output-escaping="yes"/>
              </td>
            </tr>
          </xsl:for-each>
        </table>
      </p>      
    </div>
  </xsl:template>
  
  
  <!-- XSL transformation starts here -->
  <xsl:template match="/All_Results">
    <xsl:variable name="debugmode" select="@debugmode"></xsl:variable>
    <xsl:choose>      
      <xsl:when test="$debugmode = string('true')">
        <xsl:call-template name="debug.body"/>
      </xsl:when>
      <xsl:otherwise>
        <xsl:call-template name="dvt_1.body"/>   
      </xsl:otherwise>
    </xsl:choose>
    
     
  </xsl:template>

  <!-- End of Stylesheet -->
</xsl:stylesheet>